import {
  Entity,
  PrimaryGeneratedColumn,
  Column, OneToMany,
  ManyToOne,
  JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { FactionMemberEntity } from "./faction-member.entity";

@Entity("factions")
@ManualTimestamp()
export class FactionEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ type: "varchar", length: 64, unique: true, comment: "帮派名称" })
  name!: string;

  @Column({ type: "text", nullable: true, comment: "帮派描述" })
  description!: string;

  @Column({ type: "int", default: 1, comment: "帮派等级" })
  level!: number;

  @Column({ type: "bigint", default: 0, comment: "帮派经验" })
  exp!: number;

  @Column({ type: "bigint", default: 0, comment: "帮派资金" })
  funds!: number;

  @Column({ type: "int", default: 0, comment: "成员数量" })
  memberCount!: number;

  @Column({ type: "int", default: 50, comment: "最大成员数" })
  maxMembers!: number;

  @Column({ type: "bigint", comment: "帮主ID" })
  leaderId!: number;

  @Column({ type: "text", nullable: true, comment: "帮派公告" })
  announcement!: string;

  @Column({
    type: "int",
    default: 0,
    comment: "帮派类型(1:派,2:教,3:会,4:帮,5:楼,6:阁,7:军,8:组,9:社,10:族)" })
  type!: number;

  @Column({ type: "int", default: 0, comment: "最低等级要求" })
  minLevel!: number;

  @Column({ type: "varchar", length: 255, nullable: true, comment: "帮派抗性" })
  resistance!: string;

  @Column({ type: "int", default: 1, comment: "状态(1:正常,0:解散)" })
  status!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", comment: "更新时间", nullable: true })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity, { eager: false })
  @JoinColumn({ name: "leaderId" })
  leader!: CharacterEntity;

  @OneToMany(() => FactionMemberEntity, (member) => member.faction)
  members!: FactionMemberEntity[];
}
